<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('考勤报表') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('月份')" prop="month">
        <el-date-picker
          v-model="queryParams.month"
          :clearable="false"
          style="width: 200px"
          type="month"
          :placeholder="$t('月份')"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item :label="$t('国籍')" prop="international">
        <dictSelect
          v-model="queryParams.international"
          :clearable="true"
          dictionary="hr_international"
        />
      </el-form-item>
      <el-form-item :label="$t('姓名')" prop="name">
        <el-input v-model="queryParams.name" placeholder="姓名" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
        <el-button
          v-hasPermi="['hrBase:attendance:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
        <!--                <el-button type="primary" icon="el-icon-search" size="mini" @click="initHandle">{{ $t("初始化测试") }}</el-button>-->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" border>

      <!--      <el-table-column :label="$t('日期')" align="center" show-overflow-tooltip>-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.vacationsDate) }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column
        v-for="(item, index) in titles"
        :key="index"
        :label="$t(item.dateOfMonth)"
        align="center"
        show-overflow-tooltip
      >
        <template slot="header">
          {{ $t(item.dateOfMonth) }}
        </template>
        <template slot-scope="scope">
          <div style="overflow: hidden;text-overflow: ellipsis;">
            <!--            {{ $t(scope.row[item.type]) }}-->
            {{ $t(scope.row[item.dateOfMonth]) }}
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { initAttendance, listAttendance } from '@/api/oa/hr/hrBase'
import { downLoadExcel } from '@/utils/excelDownload'
export default {
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 节假日配置表格数据
      list: [],
      titles: [],
      // 弹出层标题
      title: '休假统计',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        international: undefined,
        name: undefined,
        status: 'zz',
        month: new Date()
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.titles = []
      if (this.queryParams.month == null) {
        this.queryParams.month = new Date()
      }
      listAttendance(this.queryParams).then(response => {
        this.list = response.rows
        this.titles = response.datas
        this.total = response.total
        this.loading = false
      })
    },
    initHandle() {
      initAttendance().then(response => {
        console.log('详情', response)
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.$confirm('确定要导出吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        downLoadExcel('/hrBase/hrBase/attendanceListExport', this.queryParams)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    // 表单重置
    reset() {
      this.form = {
        year: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
      this.dateRange = undefined
    }

  }
}
</script>
